﻿Public Class frmLogin
    Dim objBLL As New BLLUsuario
    Public codigo As Integer
    Public Logado As String
    Private Sub frmLogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        objconAgenda = New ConAgenda
    End Sub
#Region "Métodos"
    Sub CarregaPropriedades()
        objBLL.plogin = txtLogin.Text
        objBLL.psenha = txtSenha.Text
    End Sub
    Sub Limpa()
        txtLogin.Text = ""
        txtSenha.Text = ""
        codigo = Nothing
        Logado = ""
    End Sub
#End Region
#Region "Botão entrar"
    Private Sub bEntrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bEntrar.Click
        Try
            If Trim(txtLogin.Text <> "" And Trim(txtSenha.Text) <> "") Then
                CarregaPropriedades()
                If (objBLL.logar()) Then
                    If objBLL.pstatus = "Ativo" Then
                        codigo = objBLL.pcodigo
                        Logado = objBLL.plogin
                        fMenu.Show()
                        Me.Hide()
                        Limpa()
                    Else
                        MsgBox("Usuário desativado, favor verificar com administrador do sistema", MsgBoxStyle.Information)
                    End If
                Else
                    MsgBox("Login/Senha inválidos", MsgBoxStyle.Critical)
                End If
            Else
                MsgBox("Favor Preencher Todos os Campos", MsgBoxStyle.Information)
            End If

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally

        End Try
    End Sub
#End Region
#Region "TextBox senha"
    Private Sub txtSenha_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtSenha.KeyPress
        If e.KeyChar = Convert.ToChar(Keys.Return) Then
            e.Handled = True
            bEntrar_Click(sender, e)
        End If
    End Sub
#End Region
#Region "TextBox login"
    Private Sub txtLogin_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtLogin.KeyPress
        If e.KeyChar = Convert.ToChar(Keys.Return) Then
            e.Handled = True
            txtSenha.Select()
        End If
    End Sub
#End Region
End Class
